package com.ruoyi.source.controller;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.ruoyi.source.api.domain.SrcBatchNum;
import com.ruoyi.source.domain.vo.SrcBatchNumVo;
import com.ruoyi.source.service.ISrcBatchNumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-07-31
 */
@RestController
@RequestMapping("/batch")
public class SrcBatchNumController extends BaseController {
    @Autowired
    private ISrcBatchNumService srcBatchNumService;

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("source:num:list")
    @GetMapping("/list")
    public TableDataInfo list(SrcBatchNum srcBatchNum) {
        startPage();
        List<SrcBatchNumVo> list = srcBatchNumService.selectSrcBatchNumList(srcBatchNum);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    /*@RequiresPermissions("source:num:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrcBatchNum srcBatchNum)
    {
        List<SrcBatchNum> list = srcBatchNumService.selectSrcBatchNumList(srcBatchNum);
        ExcelUtil<SrcBatchNum> util = new ExcelUtil<SrcBatchNum>(SrcBatchNum.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }*/

    /**
     * 获取【请填写功能名称】详细信息
     */
    @RequiresPermissions("source:num:query")
    @GetMapping(value = "/{batchId}")
    public AjaxResult getInfo(@PathVariable("batchId") Long batchId) {
        return success(srcBatchNumService.selectSrcBatchNumByBatchId(batchId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @RequiresPermissions("source:num:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrcBatchNum srcBatchNum) {
        System.err.println(JSONUtil.toJsonStr(srcBatchNum));
        return toAjax(srcBatchNumService.insertSrcBatchNum(srcBatchNum));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("source:num:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SrcBatchNum srcBatchNum) {
        System.err.println(JSONUtil.toJsonStr(srcBatchNum));
        return toAjax(srcBatchNumService.updateSrcBatchNum(srcBatchNum));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("source:num:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{batchIds}")
    public AjaxResult remove(@PathVariable Long[] batchIds) {
        return toAjax(srcBatchNumService.deleteSrcBatchNumByBatchIds(batchIds));
    }

    /**
     * 查询货物列表
     */
    @GetMapping("/gooods/list/{goodsType}")
    public TableDataInfo getGoodsList(@PathVariable String goodsType){
        List<Map<String,Object>> list =  srcBatchNumService.getGoodsList(goodsType);
        return getDataTable(list);
    }

}
